using System;

namespace Ioc.Kernel
{
    public class ContainerKey
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ContainerKey"/> class.
        /// </summary>
        /// <param name="componentName">Name of the component.</param>
        /// <param name="componentService">The component service.</param>
        public ContainerKey(string componentName, Type componentService)
        {
            ComponentName = componentName;
            ComponentService = componentService;
        }

        public string ComponentName { get; set; }
        public Type ComponentService { get; set; }

        #region Equals

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (ContainerKey)) return false;
            return Equals((ContainerKey) obj);
        }

        public bool Equals(ContainerKey obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return Equals(obj.ComponentName, ComponentName) && Equals(obj.ComponentService, ComponentService);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return ((ComponentName != null ? ComponentName.GetHashCode() : 0)*397) ^ (ComponentService != null ? ComponentService.GetHashCode() : 0);
            }
        }

        public static bool operator ==(ContainerKey left, ContainerKey right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(ContainerKey left, ContainerKey right)
        {
            return !Equals(left, right);
        }

        #endregion
    }
}